<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/rp/common/taglib.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <base href="<%=basePath%>">
    
    <title>参数设置</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	
	<script src="rp/scripts/boot.js" type="text/javascript"></script>
	
	<style type="text/css">
	   	
    </style>
	
  </head>
  
  <body class="body-fit">
  	
  	<!-- <div class="mini-splitter" style="width: 100%; height: 100%;" borderStyle="border:0;">
	    <div size="220" showCollapseButton="true" minSize="220" style="padding: 8px;">
	    	
			<form id="form1" method="post">
	    		<table>
	    			<tr>
	    				<td>参数名称：</td>
	    				<td>
	    					<input class="mini-textbox" name="preName" emptyText="必填，建议使用英文" required="true"/>
	    				</td>
	    			</tr>
	    			<tr>
	    				<td>参数值：</td>
	    				<td>
	    					<textarea class="mini-textarea" name="preValue" style="height: 100px;"></textarea>
	    				</td>
	    			</tr>
	    			<tr>
	    				<td valign="top">备注：</td>
	    				<td>
	    					<textarea class="mini-textarea" name="remark" emptyText="简要说明该参数的用途" style="height: 100px;"></textarea>
	    				</td>
	    			</tr>
	    			<tr>
	    				<td></td>
	    				<td>
	    					<a class="mini-button" onclick="submitForm()"><i class="fa fa-floppy-o fa-lg"></i> 保存</a>
	    				</td>
	    			</tr>
	    		</table>
	    	</form>
	    </div>
	    <div showCollapseButton="false">
	    	
	    </div>        
	</div> -->
	
	<div style="width:100%;">
        <div class="mini-toolbar" style="padding:0px;border-top:0;border-left:0;border-right:0;">
            <table style="width:100%;">
                <tr>
                    <td style="width:100%;">
                    	<a class="mini-button" onclick="addRow()"><i class="fa fa-plus fa-lg"></i> 新增</a>
                    	<a class="mini-button" onclick="saveRows()"><i class="fa fa-floppy-o fa-lg"></i> 保存</a>
				        <a class="mini-button mini-button-danger" onclick="removeRows()"><i class="fa fa-trash-o fa-lg"></i> 删除</a>
				       	<a class="mini-button" onclick="exportPre()"><i class="fa fa-sign-out fa-lg"></i> 导出</a>
				       	<a class="mini-button" onclick="importPre()"><i class="fa fa-sign-in fa-lg"></i> 导入</a>
				       	<!-- <a class="mini-button" onclick=""><i class="fa fa-recycle fa-lg"></i> 回收站</a> -->
                    </td>
                    <td style="white-space:nowrap;">
                    	<!-- <a class="mini-button" plain="true" 
    					onclick="openHelpWindow('')"><i class="fa fa-question-circle fa-lg"></i> 帮助</a> -->
                    </td>
                </tr>
            </table>           
        </div>
    </div>
    <div class="mini-fit">
	  	<div id="preGrid" class="mini-datagrid" 
	  		style="width: 100%; height: 100%;" borderStyle="border:0;"
	    	url="rp/system/baseData/preMng/getPreferences" idField="id" pageSize="20"
	    	allowResize="false"
	    	allowCellEdit="true" allowCellSelect="true" multiSelect="true" 
	        editNextOnEnterKey="true" editNextRowCell="true" allowCellValid="true">
		    <div property="columns">
		        <div type="indexcolumn" headerAlign="center">序号</div>
		        <div type="checkcolumn"></div>
		        <div name="preName" field="preName" vtype="required" width="80" headerAlign="center" allowSort="true">
		        	参数名称<input property="editor" class="mini-textbox" style="width:100%;" enabled="true"/>
		        </div>
		        <div name="preValue" field="preValue" width="120" headerAlign="center" allowSort="true">
		        	参数值<input property="editor" class="mini-textarea" style="width:200px; height: 80px;" minHeight="50"/>
		        </div>
		        <div name="remark" field="remark" width="200" headerAlign="center">
		        	备注<input property="editor" class="mini-textarea" style="width:200px;" minHeight="50"/>
		        </div>
		        <div field="createDate" width="100" headerAlign="center" allowSort="true" renderer="onDateRenderer">
		        	创建日期
		        </div>                
		    </div>
		</div> 
  	</div>
  	
	<script type="text/javascript">
		var grid;
		$(function(){
			mini.parse();
			grid = mini.get("preGrid");
			grid.load();
		});
		
		function addRow() {
			var newRow = {
				preName : ""
			};
			grid.addRow(newRow, 0);
			grid.beginEditCell(newRow, "preName");
		}

		function saveRows() {
			grid.validate();
			if (grid.isValid() == false) {
                var error = grid.getCellErrors()[0];
                grid.beginEditCell(error.record, error.column);
                return;
            }
			
            var data = grid.getChanges();
            var json = rp_encode(data);
            grid.loading("保存中，请稍等......");
            rp_ajax("rp/system/baseData/preMng/savePreferences", {data: json}, function(text){
            	if(text == "success"){
            		grid.reload();
            	}else{
            		grid.unmask();
            		mini.alert(text);
            	}
            });
        }
		
		function removeRows() {
			mini.confirm("确定删除记录吗？", "友情提示",
	            function (action) {
	                if (action == "ok") {
	                	var rows = grid.getSelecteds();
	                    var json = rp_encode(rows);
	                    if (rows.length > 0) {
	                    	
	                    	rp_ajax("rp/system/baseData/preMng/deletePreferences", {data: json}, function(text){
	                    		//grid.removeRows(rows, false);
	                    		grid.reload();
	                        });
	                    }
	                }
	            }
	        );
        }
		
		//导出参数
		function exportPre(){
			var rows = grid.getSelecteds();
			if(rows.length <= 0){
				mini.alert("请勾选需要导出的参数");
				return false;
			}
   	        var json = rp_encode(rows);
			mini.open({
                url: "rp/common/exportData.jsp",
                title: "导出数据", 
                width: 800, 
                height: 355,
                showMaxButton: false,
                onload: function () {
                	var iframe = this.getIFrameEl();
                  	iframe.contentWindow.initTextarea(json);
                }
            });
		}
		
		function importPre(){
			/*mini.open({
                url: "rp/system/baseData/preferencesMng/importPre.jsp",
                title: "导入参数", 
                width: 500, 
                height: 280,
                showMaxButton: false,
                onload: function () {
                	
                },
                ondestroy: function (action) {
					//grid.reload();
                }
            });*/
            mini.open({
                url: "rp/common/importData.jsp",
                title: "导入数据", 
                width: 800, 
                height: 340,
                showMaxButton: false,
                onload: function() {
                	var iframe = this.getIFrameEl();
                  	iframe.contentWindow.initImportUrl("rp/system/baseData/preMng/importPre");
                },
                ondestroy: function() {
                    grid.reload();
                }
            });
		}
	</script>
  </body>
</html>
